package com.sabm.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;

public class Account  implements java.io.Serializable, UserDetails  {


     private Integer idAccount;
     private String username;
     private String password;
     private Set<Contact> contacts = new HashSet<Contact>(0);
     private Set<Role> roles = new HashSet<Role>(0);

    public Account() {
    }

	
    public Account(String username, String password) {
        this.username = username;
        this.password = password;
    }
    public Account(String username, String password, Set<Contact> contacts) {
       this.username = username;
       this.password = password;
       this.contacts = contacts;
    }
    public Account(String username, String password, Set<Contact> contacts, Set<Role> roles) {
        this.username = username;
        this.password = password;
        this.contacts = contacts;
        this.roles = roles;
     }
   
    public Integer getIdAccount() {
        return this.idAccount;
    }
    
    public void setIdAccount(Integer idAccount) {
        this.idAccount = idAccount;
    }
    public String getUsername() {
        return this.username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    @JsonIgnore
    public String getPassword() {
        return this.password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
    @JsonIgnore
    public Set<Contact> getContacts() {
        return this.contacts;
    }
    
    public void setContacts(Set<Contact> contacts) {
        this.contacts = contacts;
    }
    //
    @JsonIgnore
    public Set<Role> getRoles() {
        return this.roles;
    }
    
    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    //
    @Override
    public Collection getAuthorities() {
        List<GrantedAuthority> l1 = new ArrayList();
        for (Role role : roles) {
            l1.add(new GrantedAuthorityImpl(role.getRole()));
        }
        return l1;
    }
    public boolean isEnabled() {
        return true;
    }
    public boolean isAccountNonExpired() {
        return true;
    }

    public boolean isCredentialsNonExpired() {
        return true;
    }

    public boolean isAccountNonLocked() {
        return true;
    }



}


